package com.huage_07.lesson_02;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class FileOutputStreamDemo {
    public static void main(String[] args)  {
        //创建字节输出流对象
        FileOutputStream fos = null;
        try {
           fos= new FileOutputStream("class1\\src\\com\\huage_07\\lesson_02\\字节输出流.txt",true);

            //调用写数据方法
//        fos.write(97);

            String str = "Hello World!";
            byte[] bytes = str.getBytes();

//        fos.write(bytes,1,5);

            fos.write(bytes);
            fos.write("\r\n".getBytes());
            fos.write("你好".getBytes());
            fos.write("\r\n".getBytes());
            fos.write("--------".getBytes());
            fos.write("\r\n".getBytes());
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if (fos!=null){
                try {
                    //释放资源
                    fos.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }

    }
}
